{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "da010a99",
   "metadata": {},
   "source": [
    "# 人脸识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cdc054a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1678938593,2f75c01c-86b2-4956-bf4f-a7d2504f1f9a',\n",
       " 'time_used': 172,\n",
       " 'faces': [{'face_token': '27664eb8de85799a912c662bcbdb663c',\n",
       "   'face_rectangle': {'top': 233, 'left': 635, 'width': 293, 'height': 293}}],\n",
       " 'image_id': 'vVrvdZ7uzM80P7N+BPfJMA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/86135/Pictures/Saved Pictures/09d7bdca5369717fc5fbb7ee338eae33.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image_base64\":img,\"api_key\":\"ffavB2gGFEhY9oZCJRPyDoNUgvIWJll1\",\"api_secret\":\"InTxWKAMqpGEnAC3TzkWEjpsQxE-Rk5p\"}\n",
    "\n",
    "request_url = request_url \n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dce3432c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
